class WithdrawConfig {
  WithdrawConfig({
    this.channels,
    this.id,
    this.cashTax,
    this.coinTax,
    this.gameTax,
  });

  List<Channel>? channels;
  int? id;
  int? cashTax;
  int? coinTax;
  int? gameTax;

  Channel? get getBankCardChannel {
    for (Channel item in (channels ?? [])) {
      if (item.isBankCard) {
        return item;
      }
    }
    return null;
  }

  List<Channel> get realChannel {
    final channel_ = <Channel>[];
    
    if (getBankCardChannel != null) {
      channel_.add(getBankCardChannel!);
    }

    if (getUsdtChannel != null) {
      channel_.add(getUsdtChannel!);
    }

    return channel_;
  }

  Channel? get getUsdtChannel {
    for (Channel item in (channels ?? [])) {
      if (item.isUsdt) {
        return item;
      }
    }
    return null;
  }

  bool get hasBankCard {
    for (Channel item in (channels ?? [])) {
      if (item.isBankCard) {
        return true;
      }
    }
    return false;
  }

  bool get hasUsdt {
    for (Channel item in (channels ?? [])) {
      if (item.isUsdt) {
        return true;
      }
    }
    return false;
  }

  factory WithdrawConfig.fromJson(Map<String, dynamic> json) => WithdrawConfig(
        channels: List<Channel>.from(json["channels"].map((x) => Channel.fromJson(x))),
        id: json["ID"],
        cashTax: json["cashTax"],
        coinTax: json["coinTax"],
        gameTax: json["gameTax"],
      );

  Map<String, dynamic> toJson() => {
        "channels": channels == null ? [] : List<dynamic>.from(channels!.map((x) => x.toJson())),
        "ID": id,
        "cashTax": cashTax,
        "coinTax": coinTax,
        "gameTax": gameTax,
      };
}

class Channel {
  Channel({
    this.channelName,
    this.cid,
    this.payType,
    this.minMoney,
    this.maxMoney,
    this.qpMinMoney,
    this.qpMaxMoney,
  });

  String? channelName;
  String? cid;
  String? payType;
  int? minMoney;
  int? maxMoney;
  int? qpMinMoney;
  int? qpMaxMoney;
  bool get isBankCard => payType?.toLowerCase() == "bankcard";
  bool get isUsdt => payType?.toLowerCase() == "usdt";

  factory Channel.fromJson(Map<String, dynamic> json) => Channel(
        channelName: json["channelName"],
        cid: json["cid"],
        payType: json["payType"],
        minMoney: json["minMoney"],
        maxMoney: json["maxMoney"],
        qpMinMoney: json["qpMinMoney"],
        qpMaxMoney: json["qpMaxMoney"],
      );

  Map<String, dynamic> toJson() => {
        "channelName": channelName,
        "cid": cid,
        "payType": payType,
        "minMoney": minMoney,
        "maxMoney": maxMoney,
        "qpMinMoney": qpMinMoney,
        "qpMaxMoney": qpMaxMoney,
      };
}
